<template>
  <!-- 变电站覆盖详情页 -->
  <div class="defect-management-box">
    <table />
    <div class="plan-header-box">
      <div class="subtitle-box startbox">
        <div class="icon"></div>
        <div class="name">变电站覆盖情况详情</div>
      </div>
      <div class="return-btn">
        <div class="return">
          <span @click="goBack"></span>
        </div>
      </div>
    </div>
    <div class="filter-box">
      <div class="filter-1">
        <el-form
          ref="elForm"
          :model="formData"
          :rules="rules"
          size="medium"
          label-width="150px"
          class="elform"
        >
          <el-row :gutter="25">
            <el-col :span="6">
              <el-row :gutter="10">
                <el-col :span="24">
                  <el-form-item label="变电站名称:" prop="time">
                    <el-select
                      v-model="formData.Substation"
                      placeholder="请选择"
                      :style="{width: '100%'}"
                      clearable
                      filterable
                    >
                      <el-option
                        v-for="item in SubstationList"
                        :key="item.index"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-row :gutter="10">
                <el-col :span="24">
                  <el-form-item label="电压等级:" prop="time">
                    <el-select
                      v-model="formData.dydj"
                      placeholder="请选择"
                      :style="{width: '100%'}"
                      clearable
                    >
                      <el-option
                        v-for="item in getDydjList"
                        :key="item.index"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-row :gutter="10">
                <el-col :span="24">
                  <el-form-item label="维护班组:" prop="time">
                    <el-select
                      v-model="formData.whbz"
                      placeholder="请选择"
                      :style="{width: '100%'}"
                      clearable
                    >
                      <el-option
                        v-for="item in getWhbzList"
                        :key="item.index"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-row :gutter="15">
                <el-col :span="24">
                  <el-form-item label="天气:">
                    <el-input v-model="formData.weather" placeholder="请输入" :style="{width: '100%'}"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-row :gutter="25">
            <el-col :span="6">
              <el-row :gutter="15">
                <el-col :span="24">
                  <el-form-item label="是否有监测设备:" prop="area">
                    <el-select
                      v-model="formData.Xsfs"
                      size="small"
                      placeholder="请选择"
                      :style="{width: '100%'}"
                      clearable
                    >
                      <el-option
                        v-for="item in sfyjcsbList"
                        :key="item.index"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-row :gutter="15">
                <el-col :span="24">
                  <el-form-item label="是否有机器人:" prop="source">
                    <el-select
                      v-model="formData.sfyjqr"
                      size="small"
                      placeholder="请选择"
                      :style="{width: '100%'}"
                      clearable
                    >
                      <el-option
                        v-for="item in sfyjqrList"
                        :key="item.index"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-row :gutter="30">
                <el-col :span="12">
                  <el-button
                    type="primary"
                    @click="submitForm"
                    class="centerbox conditionQuryBtn btn"
                    icon="el-icon-search"
                  >查询</el-button>
                </el-col>
                <el-col :span="12">
                  <el-button
                    type="primary"
                    class="centerbox conditionQuryBtn"
                    @click="excelOutput"
                  >EXCEL导出</el-button>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="self-table bigTableStyle">
      <el-table
      border
        :data="tableData"
        @selection-change="handleSelectionChange"
        :row-class-name="tableRowClassName"
        style="width:100%"
        height="100%"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.5)"
      >
        <el-table-column prop="NUM" label="序号" width="100"></el-table-column>
        <el-table-column prop="SSDSMC" label="所属地市" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="WHBZMC" label="维护班组" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="BDZMC" label="变电站名称" :show-overflow-tooltip="true" width="300"></el-table-column>
        <el-table-column prop="DMMC" label="电压等级" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="WEATHER" label="天气" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="ZNSUM" label="监测装置数量" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="JQRSUM" label="机器人与视频数量" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
    </div>
    <div class="self-pagination elPaginationStyle centerbox">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pages.page"
        :page-sizes="[10, 20, 30]"
        :page-size="pages.pageSize"
        layout="total,prev, pager, next,sizes, jumper"
        :total="pages.totalSize"
      ></el-pagination>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
// import addlistmodules from "./modules/addlistmodules.vue";
import { JointInspectionModule } from "@/store/modules/JointInspection";
//loadsh
import lodash from "lodash";
import { log } from 'three';
interface optionList {
  value: string;
  label: string;
}
interface objType {
  row: object;
  rowIndex: number;
}
interface pagesType {
  pageSize: number;
  page: number;
  totalSize: number;
}
@Component({
  components: {
    // addlistmodules,
  },
})
export default class extends Vue {
  // 弹框状态
  public dialogVisible: boolean = false;
  public management_dialogVisible: boolean = false;
  public cancel_dialogVisible: boolean = false;
  // 下拉框单位名称
  get CompanyList() {
    let CompanyList = JointInspectionModule.CompanyList || [];
    return CompanyList;
  }
  // 下拉框变电站
  get SubstationList() {
    let SubstationList = JointInspectionModule.LocalCityList || [];
    return SubstationList;
  }
  // 下拉框电压等级
  get getDydjList() {
    let getDydjList = JointInspectionModule.getDydjList || [];
    return getDydjList;
  }
  // 下拉框维护班组
  get getWhbzList() {
    let getWhbzList = JointInspectionModule.getWhbzList || [];
    if (getWhbzList && getWhbzList.length>0 && getWhbzList[0].name!='全部') {
      getWhbzList.unshift({
      name:'全部',
      code:''
      })
    }
    return getWhbzList;
  }
  // 是否有监测设备
  sfyjcsbList = [
    {
      code: "",
      name: "全部",
    },
    {
      code: "否",
      name: "否",
    },
    {
      code: "是",
      name: "是",
    },
  ];
  // 是否有机器人
  sfyjqrList = [
    {
      code: "",
      name: "全部",
    },
    {
      code: "否",
      name: "否",
    },
    {
      code: "是",
      name: "是",
    },
  ];
  loading: boolean = true;
  //table表格相关事件数据
  tableData = [
    // {
    //   BDZMC: "35kV孔村变电站",
    //   DM: "25",
    //   DMMC: "交流35kV",
    //   JQRSUM: "-",
    //   NUM: 1,
    //   OBJ_ID: "100441769",
    //   SFYJCSB: "否",
    //   SFYJQR: "否",
    //   SSDS: "8a1ea5c64bdebad1014bdebc55c80003",
    //   SSDSMC: "国网济南供电公司",
    //   WEATHER: null,
    //   WHBZMC: "变电运维班",
    //   ZNSUM: "-",
    // },
  ];
  tableSelect: Array<object> = [];
  //搜索框from表单数据
  formData: any = {
    Substation: "", //变电站名称
    dydj: "", //电压等级
    // dydjs:"",
    sfyjcsb: "", //是否有监测设备
    sfyjqr: "", //是否有机器人
    weather: "", //天气
    whbz: "", //维护班组
    bs: "",
  };
  // 前一个表单数据
  oldForm = {};
  jclxOptions: { [key: string]: any } = [];
  rules = {
    time: [],
    alarm: [],
    source: [],
    name: [],
  };
  pickerOptions = {
    shortcuts: [
      {
        text: "最近一周",
        onClick(picker: any) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近一个月",
        onClick(picker: any) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近三个月",
        onClick(picker: any) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        },
      },
    ],
  };
  $refs!: {
    elForm: any;
  };
  // 查询
  submitForm() {
    // console.log("CompanyList:",this.CompanyList)
    this.$refs.elForm.validate((valid: any) => {
      if (!valid) return;
      // TODO 提交表单
      // console.log("this.formData:", this.formData);
      this.pages.page = 1;
      this.queryAuxRealtimeList();
    });
  }

  //分页数据事件相关
  pages: { pageSize: number; page: number; totalSize: number } = {
    pageSize: 20,
    page: 1,
    totalSize: 0,
  };
  //   分页
  handleSizeChange(val: any) {
    // console.log(`每页 ${val} 条`);
    this.pages.pageSize = val;
    this.pages.page = 1;
    this.queryAuxRealtimeList();
  }
  // 分页事件
  handleCurrentChange(val: any) {
    this.pages.page = val;
    this.queryAuxRealtimeList();
  }
  // 监听查询条件变化
  @Watch("formData", { immediate: true, deep: true })
  setCdType(newForm) {
    let oldForm: any = this.oldForm;
    // 如果变电站id变化
    if (newForm.station !== oldForm.station) {
      // this.formData.jclx = "";
      this.queryTypes();
    }
    this.oldForm = lodash.cloneDeep(newForm);
  }

  // 查询测点类型
  queryTypes() {
    let form = this.formData;
    let params = {
      // station: form.station,
      type: "fk",
    };
    (this as any).$services
      .queryTypes({ data: params })
      .then((result: any) => {
        this.jclxOptions = result.data;
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 查询当前表格数据
  queryAuxRealtimeList() {
    console.log(123);
    
    // console.log("this.formData.cleartime:", this.formData.cleartime);
    var localCity = "";
    // console.log("this.CompanyList:", this.CompanyList);

    if (this.CompanyList && this.CompanyList[0] && this.CompanyList[0].code) {
      localCity = this.CompanyList[0].code;
    } else {
      localCity = "8a1ea5c64bdebad1014bdebc6047087b";
    }
    let form = {
      bdzmc: this.formData.Substation, // 变电站ID
      bs: this.formData.bs, // 标识
      dydj: this.formData.dydj, // 电压等级
      // dydjs: this.formData.dydjs, // 电压等级（传进来的）
      orgNo: localCity,
      page: this.pages.page, // 第几页
      rows: this.pages.pageSize, // 每页条数
      sfyjcsb: this.formData.sfyjcsb, // 是否有监测设备
      sfyjqr: this.formData.sfyjqr, // 是否有机器人
      weather: this.formData.weather, // 天气
      whbz: this.formData.whbz, // 维护班组
      // xsfs: "", // 巡视方式编码
    };
    (this as any).$services
      .getBdzXjfgData({ data: form, method: "get" })
      .then((result: any) => {
        // console.log("变电站覆盖情况详情页:", result);
        let data = result.data;
        this.tableData = data.rows;
        this.pages.totalSize = data.total;
        this.loading = false;
      })
      .catch((err: object) => {
        console.log(err);
        this.loading = false;
        this.$message({
          type: "warning",
          message: "服务器请求错误！",
        });
      });
  }

  // 表格选择事件
  handleSelectionChange(val: any): void {
    // console.log(val);
    this.tableSelect = val;
  }
  // 表格隔行变色
  tableRowClassName({ row, rowIndex }: objType): string {
    // console.log(row, rowIndex);
    if (rowIndex % 2 === 1) {
      return "row1";
    } else {
      return "row2";
    }
  }

  // 提示消息
  private totast(msg: string) {
    this.$message({
      message: msg,
      duration: 0,
      showClose: true,
      type: "warning",
    });
  }

  //返回按钮
  goBack() {
    window.history.back();
  }
  // 标识,如果是点击的220kv、110KV、33kv，则标识为null，如果点击的全自动巡检覆盖，则bs为jqr，如果点击的是智能管控覆盖，则bs为zn
  excelOutput() {
    // console.log('导出');
    var localCity = "";
    // console.log("this.CompanyList:", this.CompanyList);

    if (this.CompanyList && this.CompanyList[0] && this.CompanyList[0].code) {
      localCity = this.CompanyList[0].code;
    } else {
      localCity = "8a1ea5c64bdebad1014bdebc6047087b";
    }
    var forms = {
      bdzmc:  this.formData.Substation,
      bs: this.formData.bs,
      dydj: this.formData.dydj,
      // dydjs: this.formData.dydjs,
      orgNo: localCity, //所属地市id
      sfyjcsb: this.formData.sfyjcsb,
      sfyjqr: this.formData.sfyjqr,
      weather: this.formData.weather,
      whbz: this.formData.whbz,
    };
    let newForms = [];
    let formsstr = ""
    for (let key in forms) {
      newForms.push(`${key}=${forms[key]}`);
    }
    // console.log(newForms);
    formsstr = newForms.join("&");
    
    let url = `${
      (window as any).VUE_APP_BASEURL
    }/zdxs/xjzl/getBdzXjfgDataDc?${formsstr}`;
    console.log('url:',url);

    window.open(url, "_top");
  }

  mounted() {
    // 传过来的电压等级
    console.log(this.$route.query);

    if (this.$route.query.dydj) {
      let dydj = this.$route.query.dydj;
      this.getDydjList.map((v: any, i: any) => {
        if (v.name.indexOf(dydj) != -1) {
          this.formData.dydj = v.code;
        }
      });
    }
    if (this.$route.query.bs) {
      this.formData.bs = this.$route.query.bs;
    }
    // 查询表格数据
    this.queryAuxRealtimeList();
  }
}
</script>

<style lang="scss" scoped>
.defect-management-box {
  width: 100%;
  height: 100%;
  padding: 0 0.24rem;
  box-sizing: border-box;
  .plan-header-box {
    height: 0.3rem;
    margin-top: 0.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .subtitle-box {
      height: 0.3rem;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      // .icon {
      //   width: 0.16rem;
      //   height: 0.18rem;
      // background: url("../../../../assets/img/JointInspection/xjjh_subtitle_icon.png")
      //   no-repeat center center;
      // background-size: 100% 100%;
      // }
      .name {
        font-size: 0.18rem;
        margin-left: 0.06rem;
      }
    }
    .return-btn {
      height: 0.3rem;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .return {
        width: 0.9rem;
        height: 0.3rem;
        text-align: right;
        > span {
          display: inline-block;
          width: 0.9rem;
          height: 0.3rem;
          background: url(../../../../assets/img/return.png) no-repeat;
          background-size: 100% 100%;
          vertical-align: middle;
          cursor: pointer;
        }
      }
    }
  }
  .filter-box {
    height: 1.04rem;
    width: 100%;
    margin-top: 0.15rem;
    .filter-1 {
      height: 0.36rem;
      width: 100%;
      margin-top: 0.1rem;
      .elform {
        width: 100%;
        height: 100%;
      }
    }
  }
  .btn {
    margin-left: 0.32rem;
  }
  .self-table {
    height: calc(100% - 2.38rem);
    width: 100%;
    margin-top: 0.1rem;
  }
  .self-pagination {
    width: 100%;
    height: 0.6rem;
  }
}
</style>
<style lang="scss">
.defect-management-box {
  //   按钮样式
  // .el-button {
  //   width: 1.1rem;
  //   height: 0.36rem;
  //   padding: 0;
  // }
  .el-table {
    width: 100%;
    height: 100%;
  }
  // 表单输入样式设置
  .el-input--medium {
    font-size: 0.18rem;
  }
  .el-form-item__label {
    font-size: 0.18rem;
  }
  .el-select .el-input .el-input__inner {
    font-size: 0.18rem;
  }
}
</style>



